package com.ljkj.cordial.chat.dao.notify;


import com.ljkj.cordial.chat.base.ChatApp;
import com.ljkj.cordial.chat.dao.DbController;
import com.ljkj.cordial.chat.dao.SysNoticeTableDao;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.annotation.Property;

import java.io.Serializable;

/**
 * 系统通知
 */
@Entity(nameInDb = "SysNoticeTable")
public class SysNoticeTable implements Serializable {

    private static final long serialVersionUID = -7402116311807161227L;
    @Id(autoincrement = true)
    private Long id;
    // 通知ID
    @Index(unique = true)
    @Property(nameInDb = "NOTIFY_ID")
    private String notifyId;

    // 通知标题
    @Property(nameInDb = "TITLE")
    private String title;

    // 通知内容
    @Property(nameInDb = "CONTENT")
    private String content;

    // 通知作者
    @Property(nameInDb = "AUTHOR")
    private String author;

    // 通知时间
    @Property(nameInDb = "DATE")
    private String date;

    // 通知连接
    @Property(nameInDb = "URL")
    private String url;
    /**
     * 图片网络地址
     */
    @Property(nameInDb = "AVATAR_URL")
    private String imgUrl;
    /**
     * 图片本地主键id
     */
    @Property(nameInDb = "AVATAR_ID")
    private String imgId;
    @Property(nameInDb = "USER_ID")
    private String userId;

    @Generated(hash = 1311002663)
    public SysNoticeTable(Long id, String notifyId, String title, String content, String author,
                          String date, String url, String imgUrl, String imgId, String userId) {
        this.id = id;
        this.notifyId = notifyId;
        this.title = title;
        this.content = content;
        this.author = author;
        this.date = date;
        this.url = url;
        this.imgUrl = imgUrl;
        this.imgId = imgId;
        this.userId = userId;
    }

    @Generated(hash = 602354351)
    public SysNoticeTable() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNotifyId() {
        return this.notifyId;
    }

    public void setNotifyId(String notifyId) {
        this.notifyId = notifyId;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return this.content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getAuthor() {
        return this.author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getDate() {
        return this.date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getUrl() {
        return this.url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getImgUrl() {
        return this.imgUrl;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public String getImgId() {
        return this.imgId;
    }

    public void setImgId(String imgId) {
        this.imgId = imgId;
    }

    public String getUserId() {
        return this.userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public static void insert(SysNoticeTable table) {
        SysNoticeTable b = DbController.getInstance().getRead().getSysNoticeTableDao()
                .queryBuilder().where(SysNoticeTableDao.Properties.UserId.eq(ChatApp.getInstance().getUserId())
                        , SysNoticeTableDao.Properties.NotifyId.eq(table.notifyId)).unique();
        if (b != null) {
            table.setId(b.id);
        }
        DbController.getInstance().getWrite().getSysNoticeTableDao().insertOrReplace(table);
    }
}
